package org.aiforum.frountend.common;

import java.util.List;

import org.aiforum.domain.Topic;

/**
 * 分页查询
 * @author VIC
 *
 */
public class Pageing {
	
	private String actionName;// 分页查询Ation名称
	private String queryLineHql;// 查询总记录数的HQL
	private String quaryDataHql;// 查询数据的HQL
	private String keyword;//查询关键字
	private String operate;//上页或下页操作,S表示上页，X表示下页,默认为空
	private int total;//总页数
	private int line;//匹配条件的总记录数(从数据库中获取)
	private int page = 1;//当前页码,默认为1
	private int size = 8;//每页显示记录数,默认10条
	private int firstIndex;//起始索引(oracle分页数据)
	private int maxIndex;//最大索引(oracle分页数据)
	private List<Topic> topics;//返回数据
	private String message;//查询提示
	private boolean state;//查询状态,true表示有结果
	/**
	 * 计算页码
	 * @return
	 */
	public void calculationPage() {
		if("S".equalsIgnoreCase(operate)){
			// 向前翻页
			if(this.page < 1){
				// 重置到最后一页
				this.page = this.total;
			}
		}else if("X".equalsIgnoreCase(operate)){
			// 向后翻页
			if(this.page > this.total){
				// 重置到第一页
				this.page = 1;
			}
		}
	}
	/**
	 * 计算起始返回索引
	 * @return
	 */
	public int calculationFirstIndex() {
		this.firstIndex = (this.page - 1) * this.size;
		return firstIndex;
	}
	/**
	 * 计算最大返回索引
	 * @return
	 */
	public int calculationMaxIndex() {
		this.maxIndex = this.firstIndex + this.size;
		return maxIndex;
	}
	/**
	 * 计算总页码
	 */
	public void calculationTotal() {
		this.total = this.line / this.size;
		// 如果有余数则继续加一页
		if(this.line % this.size > 0){
			this.total++;
		}
	}
	public int getLine() {
		return line;
	}
	public void setLine(int line) {
		this.line = line;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public boolean isState() {
		return state;
	}
	public void setState(boolean state) {
		this.state = state;
	}
	public int getTotal() {
		return total;
	}
	public void setTotal(int total) {
		this.total = total;
	}
	public int getPage() {
		return this.page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getSize() {
		return size;
	}
	public void setSize(int size) {
		this.size = size;
	}
	public int getFirstIndex() {
		return firstIndex;
	}
	public void setFirstIndex(int firstIndex) {
		this.firstIndex = firstIndex;
	}
	public int getMaxIndex() {
		return maxIndex;
	}
	public void setMaxIndex(int maxIndex) {
		this.maxIndex = maxIndex;
	}
	public List<Topic> getTopics() {
		return topics;
	}
	public void setTopics(List<Topic> topics) {
		this.topics = topics;
	}
	
	public String getQueryLineHql() {
		return queryLineHql;
	}
	public void setQueryLineHql(String queryLineHql) {
		this.queryLineHql = queryLineHql;
	}
	public String getQuaryDataHql() {
		return quaryDataHql;
	}
	public void setQuaryDataHql(String quaryDataHql) {
		this.quaryDataHql = quaryDataHql;
	}
	public String getKeyword() {
		return keyword;
	}
	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}
	public String getOperate() {
		return operate;
	}
	public void setOperate(String operate) {
		this.operate = operate;
	}
	public String getActionName() {
		return actionName;
	}
	public void setActionName(String actionName) {
		this.actionName = actionName;
	}
	
}
